package java_thinking.unit_17._17_9_10;

import java_thinking.unit_17._17_2_6.Countries;

import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Desc:   创建一个SlowSet
 * @author: cww
 * @DateTime: 2019-04-18 22:53
 */

public class SlowSet<K> extends AbstractSet<K> {
    private List<K> keys = new ArrayList<>();

    @Override
    public boolean add(K k) {
        if (!keys.contains(k)) {
            keys.add(k);
            return true;
        }
        return false;
    }

    @Override
    public Iterator<K> iterator() {
        return keys.iterator();
    }

    @Override
    public int size() {
        return keys.size();
    }
}

class E18_SlowSet {


    public static void main(String[] args) {
        SlowSet<String> strings = new SlowSet<>();
        strings.addAll(Countries.names(10));
        strings.addAll(Countries.names(10));
        strings.addAll(Countries.names(10));
        System.out.println(strings);
    }
}
